package com.Sep_Twenty_Nine;

import java.util.ArrayList;
import java.util.List;

public class Solution401 {

    List<String> list;

    public List<String> readBinaryWatch(int turnedOn) {
        list=new ArrayList<>();
        if (turnedOn<0) return list;
        int[] nums=new int[]{8,4,2,1,32,16,8,4,2,1};
        backtracking(turnedOn,nums,0,0,0);
        return list;
    }

    public void backtracking(int turnedOn,int[] nums,int start,int hour,int minute){
        if (turnedOn==0)
        {
            if (hour>11||minute>59)
            {
                return;
            }
            StringBuilder sb=new StringBuilder();
            sb.append(hour);
            sb.append(":");
            if (minute<10)
                sb.append(0);
            sb.append(minute);
            list.add(new String(sb));
            return;
        }
        for (int i=start;i<nums.length;i++)
        {
            //说明是小时
            if (i<4)
            {
                hour+=nums[i];
            } else
            {
                minute+=nums[i];
            }
            backtracking(turnedOn-1,nums,i+1,hour,minute);
            if(i<4)
            {
                hour-=nums[i];
            }else
            {
                minute-=nums[i];
            }
        }
    }

    public static void main(String[] args) {
        Solution401 solution401=new Solution401();
        System.out.println(solution401.readBinaryWatch(1));
    }

}
